Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stack overflow in CVE-2023-31922 #157

Merged
merged 2 commits into from
Dec 1, 2023

Conversation

nickva
Copy link
Contributor

@nickva nickva commented Nov 29, 2023

isArray and proxy isArray can call each other indefinitely in a mutually recursive loop.

Add a stack overflow check in thejs_proxy_isArray function before calling JS_isArray(ctx, s->target).

Original issue: bellard/quickjs#178
CVE: https://nvd.nist.gov/vuln/detail/CVE-2023-31922

@bnoordhuis
Copy link
Contributor

Thanks for the PR. Would it be possible to add a regression test to e.g. tests/test_builtin.js? If you push the test first, we can do a before/after check; there are ASAN buildbots in the CI matrix.

@nickva
Copy link
Contributor Author

nickva commented Nov 30, 2023

@bnoordhuis thanks for taking a look!

I had added the test from the original issue bellard/quickjs#178. However it was still not working as expected. It turns out stack checking was disabled on this fork when using ASAN. I tried to re-enable it as an experiment so with make CONFIG_ASAN=ON && make test so it would pass locally. Not sure what best approach to take so thought I'd push what I had so far...

@bnoordhuis
Copy link
Contributor

#161 - let's see if it's possible to get the stack checks working under asan

@bnoordhuis
Copy link
Contributor

@nickva can you rebase on top of master?

@nickva
Copy link
Contributor Author

nickva commented Nov 30, 2023

Will do, thanks, @bnoordhuis!

@nickva nickva force-pushed the fix-stack-overflow-cve-2023-31922 branch from 1541e70 to 89dd2c2 Compare December 1, 2023 04:16
@nickva
Copy link
Contributor Author

nickva commented Dec 1, 2023

@bnoordhuis Thank you for enabling ASAN stack checking.

I rebased on master and updated the test to try to account for the fact that without ASAN isArray might just work (return true), and with ASAN, it should raise an InternalError with a "stack overflow" message.

To validate it, I commented out the fix from quickjs.c and with ASAN enabled make test aborted:

  % make test
   ...
   #253 0x10e6b3550 in js_proxy_isArray+0x2c0 (qjs:x86_64+0x1000e9550)
   #254 0x10e6b3550 in js_proxy_isArray+0x2c0 (qjs:x86_64+0x1000e9550)

SUMMARY: AddressSanitizer: stack-overflow (qjs:x86_64+0x1000e9305) in js_proxy_isArray+0x75
==86352==ABORTING
make: *** [test] Abort trap: 6

With the fix, it passed the test.

nickva added a commit to nickva/quickjs-ng that referenced this pull request Dec 1, 2023
Don't merge this is only the test from PR quickjs-ng#157
@nickva
Copy link
Contributor Author

nickva commented Dec 1, 2023

I created a separate test PR which just has the test so we can see what it would do with the tests: #165

isArray and proxy isArray can call each other indefinitely in a mutually
recursive loop.

Add a stack overflow check in the js_proxy_isArray function before calling
`JS_isArray(ctx, s->target)`.

Original issue: bellard/quickjs#178
CVE: https://nvd.nist.gov/vuln/detail/CVE-2023-31922
@nickva nickva force-pushed the fix-stack-overflow-cve-2023-31922 branch from 89dd2c2 to 2425b54 Compare December 1, 2023 04:50
Copy link
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for the PR.

@saghul saghul merged commit 6b3bed1 into quickjs-ng:master Dec 1, 2023
@saghul
Copy link
Contributor

saghul commented Dec 1, 2023

Cheers!

@nickva
Copy link
Contributor Author

nickva commented Dec 1, 2023

@bnoordhuis, @saghul thanks for starting and maintaining quickjs-ng!

@nickva nickva deleted the fix-stack-overflow-cve-2023-31922 branch December 1, 2023 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants